/*
 * To change this template, choose Tools | Templates
 * and open the template in the editor.
 */
package canteen.sys.view;

/**
 *
 * @author TNT
 */
public class ComboboxRecInfo<T> {

    private String name;
    private T keyData;

    public ComboboxRecInfo() {
    }

    private ComboboxRecInfo(String name, T keyData) {
        this.name = name;
        this.keyData = keyData;
    }

    public void setName(String name) {
        this.name = name;
    }

    public void setKeyData(T keyData) {
        this.keyData = keyData;
    }

    public T getKeyData() {
        return keyData;
    }

    public String getName() {
        return name;
    }

    @Override
    public String toString() {
        return name;
    }

    // find index of item in combo box which matches "name"
    static int findCbKeyDataIndex(javax.swing.JComboBox cb, String keyData, int ValueIfNotFound) {
        for (int i = 0, i2 = cb.getItemCount(); i < i2; ++i) {
            ComboboxRecInfo r = (ComboboxRecInfo) cb.getItemAt(i);
            if (keyData.equals(r.name)) {
                return i;
            }
        }
        return ValueIfNotFound;
    }
}
